<?php
//单元测试
class lib_unittest{
	
	private $render;
	
	private $startTime,$endTime;
	
	private $startMemory,$endMemory;
	
	private $costTime,$costMemory;
	
	public $content;
	
	public static function start($render = true){
		$instance = new self;
		ob_start();
		$instance->render = $render;
		$instance->startMemory = memory_get_usage();
		$instance->startTime = microtime(true);
		return $instance;
	}
	
	public function end(){
		$this->endMemory = memory_get_usage();
		$this->endTime = microtime(true);
		
		$this->costMemory = $this->endMemory - $this->startMemory;
		$this->costTime = $this->endTime - $this->startTime;
		
		if ($this->render){
			/*var_dump($this->startMemory,$this->startTime);
			var_dump($this->endMemory,$this->endTime);*/
			echo '<div style="text-align:left">';
			var_dump(array(
				'Cost Memory : '.($this->costMemory/1000).' KB',
				'Cost Time : '.$this->costTime.' Second'
			));
			echo '</div>';
		}else{
			$this->content = ob_get_contents();
			ob_flush();
		}
	}
	
	public static function pre($var,$func = 'var_export'){
		echo '<pre style="text-align:left;clear:both;font-size:14px;color:black;">';
		if (function_exists($func))
			echo $func($var);
		echo '</pre>';
	}
}